package com.certificationManager.client.view;

import com.certificationManager.client.presenter.view_interface.ITopView;
import com.certificationManager.client.util.UserUtils;
import com.google.gwt.event.dom.client.HasClickHandlers;
import com.google.gwt.user.client.ui.Composite;
import com.google.gwt.user.client.ui.FlexTable;
import com.google.gwt.user.client.ui.HasHorizontalAlignment;
import com.google.gwt.user.client.ui.HasVerticalAlignment;
import com.google.gwt.user.client.ui.HorizontalPanel;
import com.google.gwt.user.client.ui.Image;
import com.google.gwt.user.client.ui.Label;
import com.google.gwt.user.client.ui.Widget;

/**
 * @author Benjamin Barbier
 *
 */
public class TopView extends Composite implements ITopView {

	/** Fields */
	private final FlexTable main = new FlexTable();
	private final Image titre = new Image("includes/CM-Logo.png"); 
	private final HorizontalPanel infos = new HorizontalPanel();
	private final Label linkAbout = new Label("A"+'\u00A0'+"propos");
	private final Label linkHelp = new Label("Aide");
	Label linkDisconnect= new Label("Déconnection");
	
	public TopView() {
		
//		String email = Cookies.getCookie(CookieUtils.USERID_COOKIE);
		String email = UserUtils.getInstance().getCurrentUser().getEmail();
		
		Label separator1 = new Label(" | ");
		separator1.setStylePrimaryName("topLabel");
		Label separator2 = new Label(" | ");
		separator2.setStylePrimaryName("topLabel");
		Label separator3 = new Label(" | ");
		separator3.setStylePrimaryName("topLabel");
		
		infos.add(new Label(email));
		infos.add(separator1);
		linkHelp.setStyleName("topLabel");
		infos.add(linkHelp);
		infos.add(separator2);
		linkAbout.setStyleName("topLabel");
		infos.add(linkAbout);
		infos.add(separator3);
		linkDisconnect.setStyleName("topLabel");
		infos.add(linkDisconnect);
		
		main.setWidget(0,0,titre);
		main.setWidget(0,1,infos);
		
		this.setStyle();

		initWidget(main);
		
	}
	
	private void setStyle() {
		main.setWidth("100%");
		main.setHeight("91px");
		main.getFlexCellFormatter().setHorizontalAlignment(0, 0, HasHorizontalAlignment.ALIGN_LEFT);
		main.getFlexCellFormatter().setHorizontalAlignment(0, 1, HasHorizontalAlignment.ALIGN_RIGHT);
		main.getFlexCellFormatter().setVerticalAlignment(0, 0, HasVerticalAlignment.ALIGN_TOP);
		main.getFlexCellFormatter().setVerticalAlignment(0, 1, HasVerticalAlignment.ALIGN_TOP);
	}
	

	@Override
	public Widget getViewWidget() {
		return this;
	}

	@Override
	public HasClickHandlers getDisconnectLink() {
		return linkDisconnect;
	}

	@Override
	public HasClickHandlers getHelpLink() {
		return linkHelp;
	}
	
	@Override
	public HasClickHandlers getAboutLink() {
		return linkAbout;
	}
	
}
